<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>webWorker</title>
</head>
<body>
    <h1>webWorker测试</h1>
    <section>
        输入数值：
        <input type="number" id="num"/>
        <button onclick="calculate()">计算</button>
    </section>
    <script>
        const worker = new Worker('modules/sum.js');
        worker.onmessage = function (event) {
            alert(`值为：${event.data}!`);
        };

        function calculate () {
            let num = document.getElementById('num').value;
            worker.postMessage(num);
        }
    </script>

</body>
</html>